package com.sunbim.rsrv.util.password;

import cn.dev33.satoken.secure.SaBase64Util;
import cn.dev33.satoken.secure.SaSecureUtil;
import cn.hutool.core.text.StrBuilder;

public class Salt {

    public static String encode(String username, String password) {
        StrBuilder strBuilder = StrBuilder.create();
        strBuilder.append(username).append(password);
        // base64编码, 用作盐
        String salt = SaBase64Util.encode(strBuilder.toString());
        // md5加盐加密
        return SaSecureUtil.md5BySalt(password, salt);
    }

    public static boolean check(String username, String encodePassword, String password) {
        // 将用户名与输入的密码进行一次加密
        String md5Password = encode(username, password);
        // 比较加密后的密码与存储密码是否一致
        return encodePassword.equals(md5Password);
    }

}
